using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;

using System.Reflection;
using Gizmox.WebGUI.Common.Resources;
using Gizmox.WebGUI.Forms;

using System.IO;
using TVC.Layout;

namespace TVC.Modules.Com
{
    /// <summary>
    /// Summary description for CustomWindowPanelControl.
    /// </summary>

    [Serializable()]
    public class CAT : ModuleParent, IHostedApplication
    {
        private TabControl tabControl1;
        private TabPage tbList;
        private TabPage tbDetail;
        //private TextBox txtROLE_ID;
        //private Label lblDescription;
        //private TextBox txtUSER_NAME;
        //private TextBox txtUSER_ID;
        //private Label lbUserID;
        //private PictureBox pibROLE_ID;
        //private TextBox txtEMP_ID;
        //private Label lblDbDefault;
        //private Label lblLanguage;
        //private TextBox txtLANGUAGE;
        //private TextBox txtDB_DEFAULT;
        private DataGridView dgvList;
        //private PictureBox pibEMP_ID;
        //private BindingSource bsPOD;
        private IContainer components;
        //private TextBox txtPASS;
        //private LinkLabel lklRole;
        //private LinkLabel lklEmp;
        //private Button btnReset;

        //private MenuItem menuItem1;
        GridLayout layout = null;
        private Label label3;
        private TextBox txtLookup;
        private Label label2;
        private TextBox txtDescription;
        private TextBox txtCode;
        private Label label1;
        private Label label10;
        private Label label8;
        private Label label7;
        private TextBox txtHeader;
        private NumericUpDown nudLength;

        private Label label4;
        private Label label6;
        private Label label5;
        private GroupBox groupBox1;
        private Label label9;
        private DataGridViewTextBoxColumn colCode;
        private DataGridViewTextBoxColumn colLookup;
        private DataGridViewTextBoxColumn colDescription;
        private BindingSource bisCAT;
        private ComboBox cboNodeStatus;
        private ComboBox cboNodeLookup;
        private ComboBox cboNodeDesc;
        private ComboBox cboNodeCode;
        private CustomControl.MultiColumnCombo mcbQdCode;
        public CAT()
        {
            // This call is required by the WebGUI Form Designer.
            InitializeComponent();
            _strType = "CAT";
        }

        /// <summary> 
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose(disposing);
        }

        #region Component Designer generated code
        /// <summary> 
        /// Required method for Designer support - do not modify 
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.tabControl1 = new Gizmox.WebGUI.Forms.TabControl();
            this.tbList = new Gizmox.WebGUI.Forms.TabPage();
            this.dgvList = new Gizmox.WebGUI.Forms.DataGridView();
            this.colCode = new Gizmox.WebGUI.Forms.DataGridViewTextBoxColumn();
            this.colLookup = new Gizmox.WebGUI.Forms.DataGridViewTextBoxColumn();
            this.colDescription = new Gizmox.WebGUI.Forms.DataGridViewTextBoxColumn();
            this.bisCAT = new Gizmox.WebGUI.Forms.BindingSource(this.components);
            this.tbDetail = new Gizmox.WebGUI.Forms.TabPage();
            this.groupBox1 = new Gizmox.WebGUI.Forms.GroupBox();
            this.cboNodeStatus = new Gizmox.WebGUI.Forms.ComboBox();
            this.cboNodeLookup = new Gizmox.WebGUI.Forms.ComboBox();
            this.cboNodeDesc = new Gizmox.WebGUI.Forms.ComboBox();
            this.cboNodeCode = new Gizmox.WebGUI.Forms.ComboBox();
            this.label10 = new Gizmox.WebGUI.Forms.Label();
            this.label9 = new Gizmox.WebGUI.Forms.Label();
            this.label4 = new Gizmox.WebGUI.Forms.Label();
            this.label6 = new Gizmox.WebGUI.Forms.Label();
            this.label5 = new Gizmox.WebGUI.Forms.Label();
            this.nudLength = new Gizmox.WebGUI.Forms.NumericUpDown();
            this.label3 = new Gizmox.WebGUI.Forms.Label();
            this.label8 = new Gizmox.WebGUI.Forms.Label();
            this.txtLookup = new Gizmox.WebGUI.Forms.TextBox();
            this.label7 = new Gizmox.WebGUI.Forms.Label();
            this.label2 = new Gizmox.WebGUI.Forms.Label();
            this.txtDescription = new Gizmox.WebGUI.Forms.TextBox();
            this.txtCode = new Gizmox.WebGUI.Forms.TextBox();
            this.txtHeader = new Gizmox.WebGUI.Forms.TextBox();
            this.label1 = new Gizmox.WebGUI.Forms.Label();
            this.mcbQdCode = new TVC.Modules.CustomControl.MultiColumnCombo();
            ((System.ComponentModel.ISupportInitialize)(this.tabControl1)).BeginInit();
            this.tabControl1.SuspendLayout();
            this.tbList.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.dgvList)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.bisCAT)).BeginInit();
            this.tbDetail.SuspendLayout();
            this.groupBox1.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.nudLength)).BeginInit();
            this.SuspendLayout();
            // 
            // tabControl1
            // 
            this.tabControl1.Alignment = Gizmox.WebGUI.Forms.TabAlignment.Bottom;
            this.tabControl1.Appearance = Gizmox.WebGUI.Forms.TabAppearance.Workspace;
            this.tabControl1.Controls.Add(this.tbList);
            this.tabControl1.Controls.Add(this.tbDetail);
            this.tabControl1.Dock = Gizmox.WebGUI.Forms.DockStyle.Fill;
            this.tabControl1.Location = new System.Drawing.Point(3, 3);
            this.tabControl1.Name = "tabControl1";
            this.tabControl1.SelectedIndex = 0;
            this.tabControl1.Size = new System.Drawing.Size(601, 442);
            this.tabControl1.TabIndex = 0;
            // 
            // tbList
            // 
            this.tbList.Controls.Add(this.dgvList);
            this.tbList.Dock = Gizmox.WebGUI.Forms.DockStyle.Fill;
            this.tbList.Location = new System.Drawing.Point(4, 22);
            this.tbList.Name = "tbList";
            this.tbList.Size = new System.Drawing.Size(593, 416);
            this.tbList.TabIndex = 0;
            this.tbList.Text = "List";
            // 
            // dgvList
            // 
            this.dgvList.AllowDrag = false;
            this.dgvList.AllowUserToAddRows = false;
            this.dgvList.AutoGenerateColumns = false;
            this.dgvList.BackgroundColor = System.Drawing.Color.White;
            this.dgvList.BorderStyle = Gizmox.WebGUI.Forms.BorderStyle.FixedSingle;
            this.dgvList.ColumnHeadersHeightSizeMode = Gizmox.WebGUI.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.dgvList.Columns.AddRange(new Gizmox.WebGUI.Forms.DataGridViewColumn[] {
            this.colCode,
            this.colLookup,
            this.colDescription});
            this.dgvList.DataSource = this.bisCAT;
            this.dgvList.Dock = Gizmox.WebGUI.Forms.DockStyle.Fill;
            this.dgvList.Location = new System.Drawing.Point(0, 0);
            this.dgvList.Name = "dgvList";
            this.dgvList.RowHeadersWidth = 25;
            this.dgvList.RowTemplate.DefaultCellStyle.FormatProvider = new System.Globalization.CultureInfo("en-US");
            this.dgvList.ShowFilterRow = true;
            this.dgvList.Size = new System.Drawing.Size(593, 416);
            this.dgvList.TabIndex = 0;
            this.dgvList.RowHeaderMouseDoubleClick += new Gizmox.WebGUI.Forms.DataGridViewCellMouseEventHandler(this.dgvList_RowHeaderMouseDoubleClick);
            // 
            // colCode
            // 
            this.colCode.DataPropertyName = "Code";
            this.colCode.HeaderText = "Code";
            this.colCode.Name = "colCode";
            // 
            // colLookup
            // 
            this.colLookup.DataPropertyName = "Lookup";
            this.colLookup.HeaderText = "Look Up";
            this.colLookup.Name = "colLookup";
            // 
            // colDescription
            // 
            this.colDescription.AutoSizeMode = Gizmox.WebGUI.Forms.DataGridViewAutoSizeColumnMode.Fill;
            this.colDescription.DataPropertyName = "Description";
            this.colDescription.HeaderText = "Description";
            this.colDescription.Name = "colDescription";
            // 
            // bisCAT
            // 
            this.bisCAT.DataSource = typeof(DTO.CategoryInfo);
            // 
            // tbDetail
            // 
            this.tbDetail.Controls.Add(this.groupBox1);
            this.tbDetail.Controls.Add(this.nudLength);
            this.tbDetail.Controls.Add(this.label3);
            this.tbDetail.Controls.Add(this.label8);
            this.tbDetail.Controls.Add(this.txtLookup);
            this.tbDetail.Controls.Add(this.label7);
            this.tbDetail.Controls.Add(this.label2);
            this.tbDetail.Controls.Add(this.txtDescription);
            this.tbDetail.Controls.Add(this.txtCode);
            this.tbDetail.Controls.Add(this.txtHeader);
            this.tbDetail.Controls.Add(this.label1);
            this.tbDetail.Dock = Gizmox.WebGUI.Forms.DockStyle.Fill;
            this.tbDetail.Location = new System.Drawing.Point(0, 0);
            this.tbDetail.Name = "tbDetail";
            this.tbDetail.Size = new System.Drawing.Size(593, 416);
            this.tbDetail.TabIndex = 1;
            this.tbDetail.Text = "Detail";
            // 
            // groupBox1
            // 
            this.groupBox1.Controls.Add(this.mcbQdCode);
            this.groupBox1.Controls.Add(this.cboNodeStatus);
            this.groupBox1.Controls.Add(this.cboNodeLookup);
            this.groupBox1.Controls.Add(this.cboNodeDesc);
            this.groupBox1.Controls.Add(this.cboNodeCode);
            this.groupBox1.Controls.Add(this.label10);
            this.groupBox1.Controls.Add(this.label9);
            this.groupBox1.Controls.Add(this.label4);
            this.groupBox1.Controls.Add(this.label6);
            this.groupBox1.Controls.Add(this.label5);
            this.groupBox1.FlatStyle = Gizmox.WebGUI.Forms.FlatStyle.Flat;
            this.groupBox1.Location = new System.Drawing.Point(19, 171);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(496, 156);
            this.groupBox1.TabIndex = 5;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "QD source";
            // 
            // cboNodeStatus
            // 
            this.cboNodeStatus.AllowDrag = false;
            this.cboNodeStatus.DisplayMember = "DESCRIPTN";
            this.cboNodeStatus.FormattingEnabled = true;
            this.cboNodeStatus.Location = new System.Drawing.Point(90, 116);
            this.cboNodeStatus.Name = "cboNodeStatus";
            this.cboNodeStatus.Size = new System.Drawing.Size(123, 21);
            this.cboNodeStatus.TabIndex = 4;
            this.cboNodeStatus.ValueMember = "CODE";
            // 
            // cboNodeLookup
            // 
            this.cboNodeLookup.AllowDrag = false;
            this.cboNodeLookup.DisplayMember = "DESCRIPTN";
            this.cboNodeLookup.FormattingEnabled = true;
            this.cboNodeLookup.Location = new System.Drawing.Point(90, 90);
            this.cboNodeLookup.Name = "cboNodeLookup";
            this.cboNodeLookup.Size = new System.Drawing.Size(123, 21);
            this.cboNodeLookup.TabIndex = 3;
            this.cboNodeLookup.ValueMember = "CODE";
            // 
            // cboNodeDesc
            // 
            this.cboNodeDesc.AllowDrag = false;
            this.cboNodeDesc.DisplayMember = "DESCRIPTN";
            this.cboNodeDesc.FormattingEnabled = true;
            this.cboNodeDesc.Location = new System.Drawing.Point(90, 64);
            this.cboNodeDesc.Name = "cboNodeDesc";
            this.cboNodeDesc.Size = new System.Drawing.Size(123, 21);
            this.cboNodeDesc.TabIndex = 2;
            this.cboNodeDesc.ValueMember = "CODE";
            // 
            // cboNodeCode
            // 
            this.cboNodeCode.AllowDrag = false;
            this.cboNodeCode.DisplayMember = "DESCRIPTN";
            this.cboNodeCode.FormattingEnabled = true;
            this.cboNodeCode.Location = new System.Drawing.Point(90, 38);
            this.cboNodeCode.Name = "cboNodeCode";
            this.cboNodeCode.Size = new System.Drawing.Size(123, 21);
            this.cboNodeCode.TabIndex = 1;
            this.cboNodeCode.ValueMember = "CODE";
            // 
            // label10
            // 
            this.label10.AutoSize = true;
            this.label10.Location = new System.Drawing.Point(14, 17);
            this.label10.Name = "label10";
            this.label10.Size = new System.Drawing.Size(50, 13);
            this.label10.TabIndex = 0;
            this.label10.Text = "Code";
            // 
            // label9
            // 
            this.label9.AutoSize = true;
            this.label9.Location = new System.Drawing.Point(14, 121);
            this.label9.Name = "label9";
            this.label9.Size = new System.Drawing.Size(56, 13);
            this.label9.TabIndex = 0;
            this.label9.Text = "Node Status";
            // 
            // label4
            // 
            this.label4.AutoSize = true;
            this.label4.Location = new System.Drawing.Point(14, 43);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(50, 13);
            this.label4.TabIndex = 0;
            this.label4.Text = "Node Code";
            // 
            // label6
            // 
            this.label6.AutoSize = true;
            this.label6.Location = new System.Drawing.Point(14, 95);
            this.label6.Name = "label6";
            this.label6.Size = new System.Drawing.Size(59, 13);
            this.label6.TabIndex = 0;
            this.label6.Text = "Node Look Up";
            // 
            // label5
            // 
            this.label5.AutoSize = true;
            this.label5.Location = new System.Drawing.Point(14, 69);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(48, 13);
            this.label5.TabIndex = 0;
            this.label5.Text = "Node Desc";
            // 
            // nudLength
            // 
            this.nudLength.AutoValidate = Gizmox.WebGUI.Forms.AutoValidate.EnablePreventFocusChange;
            this.nudLength.BorderStyle = Gizmox.WebGUI.Forms.BorderStyle.Fixed3D;
            this.nudLength.CurrentValue = new decimal(new int[] {
            0,
            0,
            0,
            0});
            this.nudLength.CurrentValueChanged = false;
            this.nudLength.Location = new System.Drawing.Point(79, 130);
            this.nudLength.Name = "nudLength";
            this.nudLength.Size = new System.Drawing.Size(100, 20);
            this.nudLength.TabIndex = 4;
            this.nudLength.TextAlign = Gizmox.WebGUI.Forms.HorizontalAlignment.Left;
            this.nudLength.UpDownAlign = Gizmox.WebGUI.Forms.LeftRightAlignment.Right;
            // 
            // label3
            // 
            this.label3.AutoSize = true;
            this.label3.Location = new System.Drawing.Point(16, 41);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(35, 13);
            this.label3.TabIndex = 0;
            this.label3.Text = "Look Up";
            // 
            // label8
            // 
            this.label8.AutoSize = true;
            this.label8.Location = new System.Drawing.Point(16, 106);
            this.label8.Name = "label5";
            this.label8.Size = new System.Drawing.Size(46, 13);
            this.label8.TabIndex = 0;
            this.label8.Text = "Header";
            // 
            // txtLookup
            // 
            this.txtLookup.AllowDrag = false;
            this.txtLookup.Location = new System.Drawing.Point(79, 38);
            this.txtLookup.MaxLength = 15;
            this.txtLookup.Name = "txtLookup";
            this.txtLookup.Size = new System.Drawing.Size(100, 20);
            this.txtLookup.TabIndex = 1;
            // 
            // label7
            // 
            this.label7.AutoSize = true;
            this.label7.Location = new System.Drawing.Point(16, 132);
            this.label7.Name = "label6";
            this.label7.Size = new System.Drawing.Size(46, 13);
            this.label7.TabIndex = 0;
            this.label7.Text = "Length";
            // 
            // label2
            // 
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(16, 67);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(35, 13);
            this.label2.TabIndex = 0;
            this.label2.Text = "Description";
            // 
            // txtDescription
            // 
            this.txtDescription.AllowDrag = false;
            this.txtDescription.Location = new System.Drawing.Point(79, 64);
            this.txtDescription.Name = "txtDescription";
            this.txtDescription.Size = new System.Drawing.Size(436, 20);
            this.txtDescription.TabIndex = 2;
            // 
            // txtCode
            // 
            this.txtCode.AllowDrag = false;
            this.txtCode.Location = new System.Drawing.Point(79, 12);
            this.txtCode.MaxLength = 15;
            this.txtCode.Name = "txtCode";
            this.txtCode.Size = new System.Drawing.Size(100, 20);
            this.txtCode.TabIndex = 0;
            // 
            // txtHeader
            // 
            this.txtHeader.AllowDrag = false;
            this.txtHeader.Location = new System.Drawing.Point(79, 103);
            this.txtHeader.Name = "txtHeader";
            this.txtHeader.Size = new System.Drawing.Size(153, 20);
            this.txtHeader.TabIndex = 3;
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(16, 15);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(35, 13);
            this.label1.TabIndex = 0;
            this.label1.Text = "Code";
            // 
            // mcbQdCode
            // 
            this.mcbQdCode.AllowDrag = false;
            this.mcbQdCode.AutoScroll = false;
            this.mcbQdCode.AutoValidate = Gizmox.WebGUI.Forms.AutoValidate.Disable;
            this.mcbQdCode.Binding = null;
            this.mcbQdCode.DisplayField = null;
            this.mcbQdCode.DisplayRows = 0;
            this.mcbQdCode.Filter = false;
            this.mcbQdCode.KeyPressChk = false;
            this.mcbQdCode.Layout = null;
            this.mcbQdCode.Location = new System.Drawing.Point(90, 13);
            this.mcbQdCode.Lookup = null;
            this.mcbQdCode.MainForm = null;
            this.mcbQdCode.Name = "mcbQdCode";
            this.mcbQdCode.Size = new System.Drawing.Size(123, 20);
            this.mcbQdCode.TabIndex = 5;
            this.mcbQdCode.Value = "";
            this.mcbQdCode.ValueField = null;
            this.mcbQdCode.ComboText_Changed += new TVC.Modules.CustomControl.MultiColumnCombo.ComboChanged(this.mcbQdCode_ComboText_Changed);
            // 
            // CAT
            // 
            this.Controls.Add(this.tabControl1);
            this.DockPadding.All = 3;
            this.Location = new System.Drawing.Point(0, -10);
            this.Padding = new Gizmox.WebGUI.Forms.Padding(3);
            this.Size = new System.Drawing.Size(607, 448);
            this.Load += new System.EventHandler(this.CAT_Load);
            ((System.ComponentModel.ISupportInitialize)(this.tabControl1)).EndInit();
            this.tabControl1.ResumeLayout(false);
            this.tbList.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.dgvList)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.bisCAT)).EndInit();
            this.tbDetail.ResumeLayout(false);
            this.groupBox1.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.nudLength)).EndInit();
            this.ResumeLayout(false);

        }
        #endregion
        int idAllowEditLanguage = 1;
        int idAddNew = 53;
        int idEdit = 54;
        int idDelete = 55;
        int idTransferIn = 56;
        int idTransferOut = 57;
        int idPrint = 58;




        protected override void AllowEditLanguage()
        {
            foreach (Control x in tbDetail.Controls)
            {
                if (x is Label)
                {
                    x.DoubleClick += Control_DoubleClick;
                }
                if (x is GroupBox || x is ExpandableGroupBox || x is Panel)
                {
                    x.DoubleClick += Control_DoubleClick;
                    foreach (Control y in x.Controls)
                    {
                        if (y is Label)
                            y.DoubleClick += Control_DoubleClick;
                    }
                }
            }

            ContextMenu menu = new ContextMenu();
            menu.MenuItems.Add(new MenuItem("Edit Language"));
            dgvList.MenuClick += dgvList_MenuClick;
            tabControl1.DoubleClick += tabMain_DoubleClick;
            dgvList.ContextMenu = menu;
        }

        protected override void LoadLanguage(string language)
        {
            foreach (Control x in tbDetail.Controls)
            {
                if (x is Label)
                {
                    clsConfigurarion.GetLabel(this.ToString(), x, language);
                }
                if (x is GroupBox || x is ExpandableGroupBox || x is Panel)
                {
                    clsConfigurarion.GetLabel(this.ToString(), x, language);
                    foreach (Control y in x.Controls)
                    {
                        if (y is Label)
                            clsConfigurarion.GetLabel(this.ToString(), y, language);
                    }
                }
            }
            //clsConfigurarion.GetLabel(this.ToString(), lbUserID, language);
            //clsConfigurarion.GetLabel(this.ToString(), lblDescription, language);
            //clsConfigurarion.GetLabel(this.ToString(), lblLanguage, language);
            //clsConfigurarion.GetLabel(this.ToString(), lblDbDefault, language);
            //clsConfigurarion.GetLabel(this.ToString(), lklRole, language);
            //clsConfigurarion.GetLabel(this.ToString(), lklEmp, language);

            if (this.Parent is HeaderedPanel)
            {
                HeaderedPanel pln = this.Parent as HeaderedPanel;
                _title = clsConfigurarion.GetLabel(this.ToString(), "", null, language);
            }
        }
        public HostedToolBarElement[] GetToolBarElements()
        {
            ArrayList objElements = new ArrayList();
            if (IsPermis(idAddNew))
                objElements.Add(new HostedToolBarButton("Add New", new IconResourceHandle("Add.png"), "C"));
            if (IsPermis(idEdit))
                objElements.Add(new HostedToolBarButton("Edit", new IconResourceHandle("Edit.png"), "A"));
            if (IsPermis(idAddNew) && IsPermis(idEdit))
                objElements.Add(new HostedToolBarButton("Save", new IconResourceHandle("Save.png"), "S"));
            if (IsPermis(idAddNew))
                objElements.Add(new HostedToolBarButton("Copy", new IconResourceHandle("Copy.png"), "O"));
            if (IsPermis(idDelete))
                objElements.Add(new HostedToolBarButton("Delete", new IconResourceHandle("Delete.png"), "X"));
            objElements.Add(new HostedToolBarSeperator());
            if (IsPermis(idTransferIn))
                objElements.Add(new HostedToolBarButton("clsTransfer In", new IconResourceHandle("Down.png"), "TI"));
            if (IsPermis(idTransferOut))
                objElements.Add(new HostedToolBarButton("clsTransfer Out", new IconResourceHandle("Up.png"), "TO"));
            objElements.Add(new HostedToolBarSeperator());
            if (IsPermis(idPrint))
                objElements.Add(new HostedToolBarButton("Print", new IconResourceHandle("Print.png"), "P"));
            objElements.Add(new HostedToolBarButton("Refresh", new IconResourceHandle("Refresh.png"), "R"));

            return (HostedToolBarElement[])objElements.ToArray(typeof(HostedToolBarElement));
        }


        #region IHostedApplication Members

        public void InitializeApplication()
        {
        }

        public void addRecord()
        {

        }
        public void SetObject(object obj)
        {
        }

        public void OnToolBarButtonClick(HostedToolBarButton objButton, EventArgs objEvent)
        {
            try
            {
                sErr = "";
                string strAction = (string)objButton.Tag;

                BUS.CategoryControl ctr = new BUS.CategoryControl();
                switch (strAction)
                {
                    case "C":
                        tabControl1.SelectedTab = tbDetail;
                        RefeshForm("");
                        EnableForm(true);
                        break;
                    case "A":
                        if (dgvList.CurrentCell != null)
                        {
                            DTO.CategoryInfo info = new DTO.CategoryInfo((DataRowView)dgvList.CurrentRow.DataBoundItem);
                            if (txtCode.Text != info.Code)
                                SetData(info);

                            EnableForm(true);
                            txtCode.ReadOnly = true;
                            tabControl1.SelectedTab = tbDetail;
                        }
                        break;
                    case "S":
                        if (layout == null)
                            layout = new GridLayout(MainForm.ServerPath + "Resources\\Layout\\", MainForm.ServerPath + "Documents\\Layout\\" + GetMainForm().PODInfo.USER_ID + "\\", _strType);
                        layout.GetUpDGV(dgvList);
                        layout.SaveLayout();
                        Save(ctr);

                        break;
                    case "O":
                        if (dgvList.CurrentCell != null)
                        {
                            if (txtCode.Text == "")
                            {
                                DTO.CategoryInfo info = new DTO.CategoryInfo((DataRowView)dgvList.CurrentRow.DataBoundItem);
                                SetData(info);
                            }
                            EnableForm(true);
                            tabControl1.SelectedTab = tbDetail;
                        }
                        break;
                    case "X":
                        Delete(ctr);

                        break;
                    case "TI":
                        Forms.frmTransferIn frmTI = new Forms.frmTransferIn(_strType, GetMainForm());
                        frmTI.ShowDialog();
                        break;
                    case "TO":
                        Forms.frmTransferOut frmTO = new Forms.frmTransferOut(_strType, GetMainForm());
                        frmTO.Show();
                        break;
                    case "R":
                        RefreshList();
                        break;
                    case "P":
                        if (dgvList.CurrentCell != null)
                        {
                            DTO.CategoryInfo info = new DTO.CategoryInfo((DataRowView)dgvList.CurrentRow.DataBoundItem);
                            DataTable dt = DTO.CategoryInfo.ToDataTable();
                            dt.Rows.Add(info.ToDataRow(dt));
                            DataSet ds = new DataSet();
                            ds.Tables.Add(dt);
                            MainForm main = GetMainForm();
                            if (main != null)
                                main.PrintDataSet(ds, _strType);
                        }
                        break;
                }
                _processStatus = strAction;
                if (sErr == "")
                    ThrowMsg("Command: " + _processStatus);
            }
            catch (Exception ex)
            {
                ThrowMsg(ex.Message + Environment.NewLine + ex.Source);
            }
        }

        private void Delete(BUS.CategoryControl ctr)
        {
            if (dgvList.CurrentCell != null)
            {
                DTO.CategoryInfo info = new DTO.CategoryInfo((DataRowView)dgvList.CurrentRow.DataBoundItem);
                if (ctr.IsExist(GetMainForm().DB, info.Code))
                {
                    Forms.frmMsg frm = new Forms.frmMsg();
                    frm.FormClosed += delegate(object form, FormClosedEventArgs args)
                    {
                        if (((Gizmox.WebGUI.Forms.Form)form).DialogResult == DialogResult.OK)
                        {
                            ctr.Delete(GetMainForm().DB, info.Code);
                            if (sErr == "")
                            {
                                GetMainForm().RemoveRecord(_strType, ((DataRowView)dgvList.CurrentRow.DataBoundItem).Row);
                                EnableForm(false);
                                Rebind();
                                sErr = "Delete record " + info.Code + " successful";
                            }

                            ThrowMsg(sErr);

                        }

                    };
                    frm.ShowMsg("Do you want to delete " + info.Code + "?");

                }
                else
                    sErr = clsConfigurarion.GetErrMsg("E0002", language);// "Data is not exist";
            }
        }

        private void RefreshList()
        {
            GetMainForm().LoadDataTable(_strType);
            Rebind();
            if (layout == null)
                layout = new GridLayout(MainForm.ServerPath + "Resources\\Layout\\", MainForm.ServerPath + "Documents\\Layout\\" + GetMainForm().PODInfo.USER_ID + "\\", _strType);
            layout.ResetLayout();
            layout.SetUpDGV(dgvList);
        }

        private void Save(BUS.CategoryControl ctr)
        {
            if (tabControl1.SelectedTab == tbDetail)
            {
                DTO.CategoryInfo info = GetData();
                if (_processStatus == "A")
                {
                    if (ctr.IsExist(GetMainForm().DB, txtCode.Text))
                    {
                        sErr = ctr.Update(info);
                        UpdateRecord(info);
                        sErr = "Update record " + txtCode.Text + " successful";
                    }
                    else
                        sErr = clsConfigurarion.GetErrMsg("E0002", language);// "Data is not exist";
                }
                else if (_processStatus == "C" || _processStatus == "O")
                {
                    if (!ctr.IsExist(GetMainForm().DB, txtCode.Text))
                    {
                        ctr.Add(info, ref sErr);
                        UpdateRecord(info);
                        sErr = "Add record " + txtCode.Text + " successful";
                    }
                    else
                        sErr = clsConfigurarion.GetErrMsg("E0007", language);
                }

                ThrowMsg(sErr);

            }
        }

        private void UpdateRecord(DTO.CategoryInfo info)
        {
            GetMainForm().GetTable(_strType).BeginLoadData();
            GetMainForm().UpdateRecord(_strType, info.ToDataRow(GetMainForm().GetTable(_strType)).ItemArray, LoadOption.OverwriteChanges);
            GetMainForm().GetTable(_strType).EndLoadData();
            EnableForm(false);
            Rebind();
        }

        private void Rebind()
        {
            bisCAT.DataSource = GetMainForm().GetTable(_strType);
        }

        private void ThrowMsg(string sErr)
        {
            BaseForm x = this.Parent.Parent as BaseForm;
            if (x != null)
            {
                x.SetMsg(sErr);
            }
        }

        private DTO.CategoryInfo GetData()
        {
            return new DTO.CategoryInfo(GetMainForm().DB
                , txtCode.Text
                , txtLookup.Text
                , txtDescription.Text
                , txtHeader.Text
                , Convert.ToInt32(nudLength.Value)
                , mcbQdCode.Value
                , cboNodeCode.SelectedValue == null ? "" : cboNodeCode.SelectedValue.ToString()
                , cboNodeDesc.SelectedValue == null ? "" : cboNodeDesc.SelectedValue.ToString()
                , cboNodeLookup.SelectedValue == null ? "" : cboNodeLookup.SelectedValue.ToString()
                , cboNodeStatus.SelectedValue == null ? "" : cboNodeStatus.SelectedValue.ToString()
                );

        }

        private void EnableForm(bool p)
        {
            txtCode.ReadOnly = !p;
            txtLookup.ReadOnly = !p;
            txtDescription.ReadOnly = !p;
            txtHeader.ReadOnly = !p;
            nudLength.ReadOnly = !p;
            mcbQdCode.Enabled = p;
            cboNodeCode.Enabled = p;
            cboNodeDesc.Enabled = p;
            cboNodeLookup.Enabled = p;
            cboNodeStatus.Enabled = p;

        }

        private void SetData(DTO.CategoryInfo info)
        {
            txtCode.Text = info.Code;
            txtLookup.Text = info.Lookup;
            txtDescription.Text = info.Description;
            txtHeader.Text = info.Header;
            nudLength.Value = info.Length;
            mcbQdCode.Value = info.QdCode;
            if (info.QdCode != "")
            {
                BUS.LIST_QDDControl qddctr = new BUS.LIST_QDDControl();
                DataTable dt = qddctr.GetALL_LIST_QDD_By_QD_ID(GetMainForm().DB, mcbQdCode.Value, ref sErr);
                cboNodeCode.DataSource = dt.Copy();
                cboNodeDesc.DataSource = dt.Copy();
                cboNodeLookup.DataSource = dt.Copy();
                cboNodeStatus.DataSource = dt.Copy();
            }
            cboNodeCode.SelectedValue = info.NodeCode;
            cboNodeDesc.SelectedValue = info.NodeDesc;
            cboNodeLookup.SelectedValue = info.NodeLookup;
            cboNodeStatus.SelectedValue = info.NodeStatus;
        }

        private void RefeshForm(string str)
        {
            txtCode.Text = str;
            txtLookup.Text = str;
            txtDescription.Text = str;
            txtHeader.Text = str;
            nudLength.Value = 0;
            mcbQdCode.Value = str;
            cboNodeCode.SelectedValue = null;
            cboNodeDesc.SelectedValue = null;
            cboNodeLookup.SelectedValue = null;
            cboNodeStatus.SelectedValue = null;
        }

        #endregion

        private void CAT_Load(object sender, EventArgs e)
        {
            dgvList.AutoGenerateColumns = false;
            if (!GetMainForm().IsContainsTables(_strType))
                GetMainForm().LoadDataTable(_strType);
            Rebind();
            layout = new GridLayout(MainForm.ServerPath + "Resources\\Layout\\", MainForm.ServerPath + "Documents\\Layout\\" + GetMainForm().PODInfo.USER_ID + "\\", _strType);
            //layout.LoadLayout();
            layout.SetUpDGV(dgvList);

            if (!GetMainForm().IsContainsTables("QD"))
                GetMainForm().LoadDataTable("QD");
            mcbQdCode.Binding = GetMainForm().GetTable("QD");
            GridLayout alayout = new GridLayout(MainForm.ServerPath + "Resources\\Layout\\", String.Format("{0}Documents\\Layout\\{1}\\", MainForm.ServerPath, GetMainForm().PODInfo.USER_ID), "QD");
            GetMainForm().InitMultiComboBox(mcbQdCode, alayout, "DESCRIPTN", "QD_ID");
            EnableForm(false);
            if (idAllowEditLanguage >= GetMainForm().Permission.Length || GetMainForm().Permission[idAllowEditLanguage] == 'Y')
                AllowEditLanguage();
        }


        private void dgvList_RowHeaderMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (dgvList.CurrentCell != null)
            {
                DTO.CategoryInfo info = new DTO.CategoryInfo((DataRowView)dgvList.CurrentRow.DataBoundItem);
                SetData(info);
                EnableForm(false);
                tabControl1.SelectedTab = tbDetail;
                _processStatus = "V";
            }
        }
        public string GetLanguage()
        {
            return language;
        }

        private void mcbQdCode_ComboText_Changed(object sender, CustomControl.MultiColumnCombo.ComboChangedEventArgs e)
        {
            BUS.LIST_QDDControl qddctr = new BUS.LIST_QDDControl();
            DataTable dt = qddctr.GetALL_LIST_QDD_By_QD_ID(GetMainForm().DB, mcbQdCode.Value, ref sErr);
            DataTable dtSel = dt.Clone();
            foreach (DataRow row in dt.Rows)
            {
                if ((bool)row["IS_FILTER"] == false)
                {
                    DataRow newRow = dtSel.NewRow();
                    newRow.ItemArray = row.ItemArray;
                    dtSel.Rows.Add(newRow);
                }
            }
            cboNodeCode.DataSource = dtSel.Copy();
            cboNodeDesc.DataSource = dtSel.Copy();
            cboNodeLookup.DataSource = dtSel.Copy();
            cboNodeStatus.DataSource = dtSel.Copy();
        }



    }
}
